/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.countrytag;

import com.apt.bean.Countries;
import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 *
 * @author Bach
 */
public class GetCountry {

    public static HashMap<Integer, Countries> getListCountries() {
        HashMap<Integer, Countries> listFB = new HashMap<Integer, Countries>();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection conn = null;
        String query = "SELECT [Country_Id]\n"
                + "      ,[Country_Status]\n"
                + "      ,[Country_Name]\n"
                + "  FROM [Matrimony].[dbo].[Countries]";
        try {
            conn = Connect_DB.getConnection();
            if (conn != null) {
                ps = conn.prepareStatement(query);
                rs = ps.executeQuery();
                int key = 1;
                String country_Id;
                String country_Status;
                String country_Name;

                while (rs.next()) {
                    country_Id = rs.getString("Country_Id");
                    country_Status = rs.getString("Country_Status");
                    country_Name = rs.getString("Country_Name");

                    Countries fb = new Countries(country_Id, country_Status, country_Name);
                    listFB.put(key, fb);
                    key++;
                }
            } else {
                System.out.println("Connect is null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(rs, null, ps, conn);
        }
        return listFB;
    }
}
